package com.tianma315.admin.marshalling.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.common.base.CoreServiceImpl;
import org.springframework.stereotype.Service;

import com.tianma315.admin.marshalling.dao.MarshallingDao;
import com.tianma315.admin.marshalling.domain.MarshallingDO;
import com.tianma315.admin.marshalling.service.MarshallingService;

import java.util.List;

/**
 * 
 * <pre>
 * 班组
 * </pre>
 * <small> 2019-05-29 15:29:12 | Aron</small>
 */
@Service
public class MarshallingServiceImpl extends CoreServiceImpl<MarshallingDao, MarshallingDO> implements MarshallingService {

    @Override
    public Page<MarshallingDO> getMarshallingDOPage(Integer pageNumber, Integer pageSize, MarshallingDO marshallingDTO) {
        // 查询列表数据
        Page<MarshallingDO> page = new Page<>(pageNumber, pageSize);

        Wrapper<MarshallingDO> wrapper = new EntityWrapper<MarshallingDO>();
        wrapper.eq("state",0);
        wrapper.like("marshalling_name",marshallingDTO.getMarshallingName());
        wrapper.orderBy("marshalling_id",false);
        page = selectPage(page, wrapper);
        int total = selectCount(wrapper);
        page.setTotal(total);
        return page;
    }

    @Override
    public Boolean addMarshallingDO(MarshallingDO marshallingDO) {
        marshallingDO.setState(0);
        return insert(marshallingDO);
    }

    @Override
    public Boolean deleteMarshallingDO(Integer id) {
        MarshallingDO marshallingDO = new MarshallingDO();
        marshallingDO.setState(1);
        marshallingDO.setMarshallingId(id);
        return updateById(marshallingDO);
    }

    @Override
    public List<MarshallingDO> getMarshallingList() {
        Wrapper<MarshallingDO> wrapper = new EntityWrapper();
        wrapper.eq("state",0);
        List<MarshallingDO> marshallingDOList = selectList(wrapper);
        return marshallingDOList;
    }
    @Override
    public List<MarshallingDO> getMarshallingList(MarshallingDO marshallingDO) {
        Wrapper<MarshallingDO> wrapper = new EntityWrapper();
        wrapper.eq("state",0);
        wrapper.like("marshalling_name",marshallingDO.getMarshallingName());
        List<MarshallingDO> marshallingDOList = selectList(wrapper);
        return marshallingDOList;
    }
}
